<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <link rel="shortcut icon" href="pics/title.ico" type="image/x-icon"/>
  <meta name="keywords" content="数据共享平台">
  <title>数据共享平台</title>
  <link rel="stylesheet" type="text/css" href="style/main.css"></link>
  <script type="text/javascript" src="script/main.js"></script>
</head>

<body onload="init()">

  <div id="header" class="header">
    <div class="title_img_div"><img src="pics/title.png" class="title_img"></img></div>
    <div id="title" class="title"><span>Data Sharing Platform</span></div>
    <div id="title_info" class="title_info">
      This Website is used for sharing what you thought was funny and interesting! But take care about your comments for your local policy.
      &nbsp;&nbsp; -- @Raven
      <br/>
      <a href="#" class="log_link">Login</a>&nbsp;&nbsp;<a href="#" class="log_link">Sign Up</a>
    </div>
  </div>

  <div id="content" class="content">
    <div id="say_container" class="say_container">
      <div id="publish" style="text-align:center;">
        <form id="publish_form" action="handle.php" method="post" enctype="multipart/form-data">
          <textarea rows="8" cols="128" id="publish_content" name="publish_content" maxlength="1024"></textarea>
          <p/>
          <input id="image_file" type="file" id="publish_picture" name="publish_picture" />
          <input type="submit" value="Publish" />
        </form>
      </div>

      <div id="details">

        <?php
        // page
        if ($_GET['page'] == "") {
          $page = 1;
        } else {
          $page = $_GET['page'];
        }

        if ($page < 1) {
          $page = 1;
        }

        $COUNT = 10;
        $begin_index = $COUNT * ($page - 1);

        // page

        $con = mysql_connect("localhost","root","123456");
        if (!$con) {
          echo "Database error<br/>";
        } else {
          mysql_select_db("platform", $con);

          $result = mysql_query("SELECT * FROM publish ORDER BY pid DESC limit " . $begin_index . ", " . $COUNT);

          while($row = mysql_fetch_array($result)) {
            echo "<div class='details_border'>";
            echo "<div class='details_uname'>User IP : " . $row['uname'] . "</div>";
            echo "<div class='details_content'>" . $row['content'] . "</div>";
            if ($row['picture'] != "") {
              echo "<div class='details_picture'><img class='details_picture_img' src='" . $row['picture'] . "'></img></div>";
            }

            // comments
            echo "<div class='details_comments'>";
            // show comments
            $comments_res = mysql_query("SELECT * FROM comments WHERE pid=" . $row[pid] . " ORDER BY cid DESC");
            while ($row2 = mysql_fetch_array($comments_res)) {
              echo "<div>";
              echo "<span style='color:rgb(46, 103, 177); font-size:0.8rem;'>" . $row2['uname'] .  " : </span>";
              echo "<span style='font-size:1.0rem;'>" . $row2['content'] . "</span>";
              echo "</div>";
            }
            // form
            echo "<form action='comments.php' method='post'>";
            echo "<input type='hidden' name='pid' value='" . $row['pid'] . "' />";
            echo "<input type='text' style='width:600px;' name='comment' />";
            echo "<input type='submit' value='comment' />";
            echo "<input type='hidden' value='" . $page . "' name='page' />";
            echo "</form>";
            echo "</div>";

            echo "</div>";
          }

          $temp = mysql_query("select count(*) from publish");
          $row3 = mysql_fetch_array($temp);
          $all_records = $row3["count(*)"];
          mysql_close($con);

          echo "<div style='font-size:1.2rem; text-align:center;'>";

          if ($page > 1) {
            echo "<a href='http://10.120.137.109/platform/index.php?page=" . ($page - 1) . "'>last page</a>";
          }

          echo "&nbsp;&nbsp;&nbsp;&nbsp;";

          if ($page > 0 && ($page * $COUNT) < $all_records) {
            echo "<a href='http://10.120.137.109/platform/index.php?page=" . ($page + 1) . "'>next page</a>";
          }

          echo "</div>";
        }
        ?>


      </div>
    </div>
  </div>

  <div id="footer" class="footer">
    Tech by @Raven (kissdarkwind@gmail.com) <br/>
    All rights reserved from 2014 ~ future :)
  </div>

</body>

</html>